package com.ruoyi.user.api.factory;

import com.ruoyi.common.core.domain.R;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.user.api.RemoteUserMessageService;
import com.ruoyi.user.api.domain.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

import static com.ruoyi.common.core.web.domain.AjaxResult.error;

/**
 * 消息服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteUserMessageFallbackFactory implements FallbackFactory<RemoteUserMessageService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserMessageFallbackFactory.class);

    @Override
    public RemoteUserMessageService create(Throwable throwable)
    {
        log.error("消息通知服务调用失败:{}", throwable.getMessage());
        return new RemoteUserMessageService()
        {
            @Override
            public AjaxResult addBatch(@RequestBody List<Message> messages, String source)
            {
                return error("消息远程调用失败:");
            }
        };
    }
}
